package states 
{
	import flash.display.Shape;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFormatAlign;
	import flash.utils.getDefinitionByName;
	
	import assets.AssetsUI;
	
	import org.despair2D.control.KeyboardManager;
	import org.despair2D.control.TouchManager;
	import org.despair2D.control.ZMouseEvent;
	import org.despair2D.model.BooleanProperty;
	import org.despair2D.ui.Button;
	import org.despair2D.ui.ButtonType;
	import org.despair2D.ui.CheckBox;
	import org.despair2D.ui.DespairUI;
	import org.despair2D.ui.Fusion;
	import org.despair2D.ui.ImageButton;
	import org.despair2D.ui.ImageCheckBox;
	import org.despair2D.ui.LabelButton;
	import org.despair2D.ui.UIState;
	import org.despair2D.ui.core.IComponent;
	import org.despair2D.ui.events.ManipulateEvent;
	import org.despair2D.ui.layout.SpaceType;
	import org.despair2D.ui.puppet.DisplayObjectContainerPuppet;

public class StartingState extends UIState 
{
	
	private var boo:BooleanProperty
	
	override public function enter( stateArgs:Array ):void
	{
		var img:ImageButton,img2:ImageButton,img3:ImageButton
		var icb:ImageCheckBox,icb2:ImageCheckBox,icb3:ImageCheckBox
		var B:Button
		var lb:LabelButton
		var cb:CheckBox,cb2:CheckBox,cb3:CheckBox
		var text:TextField
		var content:Fusion
		
		content = new Fusion()
		this.fusion.addElement(content)
		content.spaceWidth = 600
		content.spaceHeight = 500
		
		/////////////////////////////////
		// ImageButton !!
		/////////////////////////////////
		img = new ImageButton('AT_btn_yellow_1')
		content.addElement(img, 50, 70)
		img.spaceWidth = img.width
		img.spaceHeight = img.height
		text = new TextField()
		text.text = 'button'
		text.autoSize = TextFormatAlign.LEFT
		img.container.addChild(text)
		img.addEventListener(ManipulateEvent.CLICK, function(e:ManipulateEvent):void
		{
			trace('[ImageButton1]')
		})
		img = new ImageButton('AT_btn_yellow_2')
		content.addElement(img, 0,0,SpaceType.A_TOP | SpaceType.A_RIGHT)
		img.addEventListener(ManipulateEvent.CLICK, function(e:ManipulateEvent):void
		{
			trace('[ImageButton2]')
		})
		img = new ImageButton('AT_btn_yellow_3')
		content.addElement(img, 0,0,SpaceType.A_TOP | SpaceType.A_RIGHT)
		img.addEventListener(ManipulateEvent.CLICK, function(e:ManipulateEvent):void
		{
			trace('[ImageButton3]')
		})
		
		/////////////////////////////////
		// ImageCheckBox !!
		/////////////////////////////////
		icb = new ImageCheckBox('AT_checkbox_1')
		content.addElement(icb, 0, 0, SpaceType.A_TOP | SpaceType.A_RIGHT)
		icb.addEventListener(Event.CHANGE, function(e:Event):void
		{
			boo.value = (e.target as ImageCheckBox).selected
		})
		icb2 = new ImageCheckBox('AT_checkbox_2', false, false, true)
		content.addElement(icb2, 0, 0, SpaceType.A_TOP | SpaceType.A_RIGHT)
		icb2.addEventListener(Event.CHANGE, function(e:Event):void
		{
			boo.value = (e.target as ImageCheckBox).selected
		})
		icb3 = new ImageCheckBox('AT_checkbox_3')
		content.addElement(icb3, 0, 0, SpaceType.A_TOP | SpaceType.A_RIGHT)
		icb3.addEventListener(Event.CHANGE, function(e:Event):void
		{
			boo.value = (e.target as ImageCheckBox).selected
		})
		
		/////////////////////////////////
		// Button !!
		/////////////////////////////////
		B = new Button('Btn_A');
		content.addElement(B,0,0,SpaceType.A_TOP | SpaceType.A_RIGHT)
		B.movieClip.width = 150
		B.movieClip.height = 60
		B.addEventListener(ManipulateEvent.CLICK, function():void
		{
			lb.interactive = !lb.interactive
			cb.interactive = !cb.interactive
			icb.interactive = !icb.interactive
			img.interactive = !img.interactive
		})
		
		/////////////////////////////////
		// LabelButton !!
		/////////////////////////////////
		lb = new LabelButton('Btn_A', 'BDemo');
		content.addElement(lb, 0,0,SpaceType.A_BOTTOM | SpaceType.A_LEFT)
		lb.addEventListener(ManipulateEvent.CLICK, function onCallback(e:ManipulateEvent) : void
		{
			var c:IComponent = e.target as IComponent
			trace(c.layer)
		})
		
		// CheckBox
		cb = new CheckBox('Select_A', false, true)
		content.addElement(cb, 0,0,SpaceType.A_BOTTOM | SpaceType.A_LEFT)
		cb.addEventListener(Event.CHANGE, function(e:Event):void
		{
			boo.value = cb.selected
			trace('[CheckBox] - ' + cb.selected)
		})
		
		boo = new BooleanProperty()
		boo.binding(function():void
		{
			icb.selected = icb2.selected = icb3.selected = cb.selected = boo.value
			
		}, false)
		
		var thumb:Fusion
		var doc:DisplayObjectContainerPuppet
		var shape:Shape
		
		//KeyboardManager.getInstance().getState().addStraightPressListener('W', function():void
		//{
			//scrollBarB.contentWidth += 100
		//})
		//KeyboardManager.getInstance().getState().addStraightPressListener('S', function():void
		//{
			//scrollBar.contentHeight += 100
		//})
		
		//TouchManager.getInstance().addEventListener(ZMouseEvent.MOUSE_RELEASE, function():void
		//{
			//trace(TouchManager.getInstance().offsetX + ' | ' + TouchManager.getInstance().offsetY)
		//})
	}
	
	override public function exit():void
	{
		KeyboardManager.getInstance().getState().removeAllStraightPressListeners('W')
		KeyboardManager.getInstance().getState().removeAllStraightPressListeners('S')
		boo.dispose()
		boo = null
	}

}

}